/**
 * Created by sofwu on 2016/12/22 0022.
 */
import logger from '../utils/logger'

export function getUserKeywordData() {
  return global.userKeywordData;
}


export function setUserKeywordData(userKeywordData) {
  global.userKeywordData = userKeywordData;
}


export function remUserKeywordData() {
  global.userKeywordData = null
  saveUKD([])
}

//是否登录
export function isUserKeywordData(){
  const userKeywordData = getuserKeywordData();

  logger.info('auth token:', userKeywordData);
  if(userKeywordData) return true;
  else return false;
}

// //登录系统
export function saveUKD(data){
  if(!data){
    logger.warn('Login userkeywordData Error!')
    return false
  }

  //保存token信息到storage中
  storage.save({
    key: 'userKeywordData',
    data: data,
    expires: null
  });
  //保存token到内存中
  setUserKeywordData(data);
  logger.info('saveUKD Success', data)
  return true
}